<?php

namespace App\Http\Requests\Admin\Customer\Store;

use App\Http\Requests\ApiRequest;
use App\Models\Store\Store;
use App\Services\Locale\Language;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\UploadedFile;

/**
 * @property string name
 * @property UploadedFile store_img
 * @property string remark
 * @property string phone
 * @property string address
 * @property int type
 * @property string account
 * @property string password
 * @property string province
 * @property string city
 * @property string district
 * @property string email
 * @property string has_youzan
 * @property string youzan_authorizer_id
 */
class StoreStoreRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $data = [
            'name'      => 'required|string|max:'.self::MAX_STRING,
            'account'   => 'required|string|unique:store_admins,account|max:'.self::MAX_STRING,
            'password'  => 'required|string|min:6|max:'.self::MAX_STRING,
            'store_img' => 'nullable|file|max:2048',
            'email'     => 'nullable|email|unique:store_admins,email',
            'address'   => 'required|string|max:'.self::MAX_STRING,
//            'province'  => 'required|string',
//            'city'      => 'required|string',
//            'district'  => 'required|string',
            'remark'    => 'nullable|string|max:'.self::MAX_STRING,
            'type'      => 'required|int|in:1,2',
            'phone'     => ['required', 'string', 'max:'.self::MAX_STRING],

            'has_youzan'  => 'nullable|int|in:0,1',
        ];

//        if (app()->getLocale() === Language::ZH_CN) {
//            $data['phone'] = ['required', 'regex:/^1[34578][0-9]{9}$|^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/'];
//        } else {
//            $data['phone'] = ['required', 'string'];
//        }

        return $data;
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'name.*'       => '店铺名称必填字符串',
//            'account.*'    => '账号已注册，请尝试其他账号',
//            'phone.*'      => '店铺手机号必须是合法的',
//            'password.*'   => '店铺超管的手机号必须是合法的',
//            'store_img.*'  => '店铺的头像必须是上传图片',
//            'email.*'      => '店铺的邮箱必须是合法的邮箱',
//            'address.*'    => '店铺的地址必须是字符串',
//            'remark.*'     => '店铺的备注信息',
//            'type.*'       => '店铺的类型必须是1或2',
//        ];
//    }
}
